package com.ym.jiujiangeyou.adapter;

import java.util.List;
import com.ym.jiujiangeyou.R;
import com.ym.jiujiangeyou.adapter.SceneryListAdapter.ViewHolder;
import com.ym.jiujiangeyou.entity.Hotel;
import com.ym.jiujiangeyou.entity.Scenery;
import com.ym.jiujiangeyou.util.Constants;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author 叶铭
 * @email yeming_1001@163.com
 * @version V1.0
* @Description: 收藏列表适配器 
*/
public class CollectListAdapter extends BaseAdapter {

	private List<Scenery> list;
	private LayoutInflater inflater;
	private Context context;
	private List<Hotel> list1;
	private int flag;
	private boolean isDel = false ;

	public CollectListAdapter(Context context, int flag) {
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.flag = flag;
	}

	public void setIsDel(boolean isDel){
		this.isDel = isDel ;
	}
	
	public void setSceneryData(List<Scenery> list) {
		this.list = list;
	}

	public void setHotelData(List<Hotel> list1) {
		this.list1 = list1;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		switch (flag) {
		case Constants.LISTVIEW_ACTION_GET_SCENERY:
			return list.size() ;
		case Constants.LISTVIEW_ACTION_GET_HOTEL:
			return list1.size() ;
		}
		return list.size();

	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		switch (flag) {
		case Constants.LISTVIEW_ACTION_GET_SCENERY:
			return list.get(position) ;
		case Constants.LISTVIEW_ACTION_GET_HOTEL:
			return list1.get(position) ;
		}
		return list.get(position);

	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;

	}

	@Override
	public int getItemViewType(int position) {
		return flag;
	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		int temp = this.flag;
		switch (temp) {
		case Constants.LISTVIEW_ACTION_GET_SCENERY:
			return getSceneryView(position, convertView);
		case Constants.LISTVIEW_ACTION_GET_HOTEL:
			return getHotelView(position, convertView);
		default:
			break;
		}
		return getSceneryView(position, convertView);
	}

	/**
	 * @param position
	 * @param view
	 * @return
	 * @retur View
	 * @Description: 景点view
	 */
	@SuppressWarnings("unused")
	private View getSceneryView(int position, View view) {
		ViewHolder viewHolder;
		// View view ;
		if (view == null) {
			viewHolder = new ViewHolder();
			view = inflater.inflate(R.layout.collect_list_item, null);
			viewHolder.textView1 = (TextView) view
					.findViewById(R.id.collect_name);
			viewHolder.img = (ImageView) view.findViewById(R.id.del_img_item) ;
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) view.getTag();
		}
		
		viewHolder.textView1.setText(list.get(position).getName().toString());
		if(this.isDel){
			viewHolder.img.setBackgroundResource(R.drawable.delete_normal) ;
		}else{
			
		}
		return view;
	}

	/**
	 * @param position
	 * @param view
	 * @return
	 * @retur View
	 * @Description: 住宿view
	 */
	private View getHotelView(int position, View view) {
		ViewHolder viewHolder;
		// View view ;
		if (view == null) {
			viewHolder = new ViewHolder();
			view = inflater.inflate(R.layout.collect_list_item, null);
			viewHolder.textView1 = (TextView) view
					.findViewById(R.id.collect_name);
			viewHolder.img = (ImageView) view.findViewById(R.id.del_img_item) ;
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) view.getTag();
		}
		viewHolder.textView1.setText(list1.get(position).getName().toString());
		if(this.isDel){
			viewHolder.img.setBackgroundResource(R.drawable.delete_normal) ;
		}else{
			
		}
		return view;
	}

	class ViewHolder {
		TextView textView1;
		ImageView img ;
	}

}
